# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  
@software: PyCharm 
@file: decorator_class_method.py 
@time: 2019/2/25 10:33
"""
'''
Decorator as an instance method
装饰器作为实例方法
'''

from functools import wraps

class A:
    # Decorator as an instance method
    # 装饰器作为实例方法调用
    def decorator1(self, func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            print("Decorator 1")
            return func(*args, **kwargs)
        return wrapper

    # Decorator as a class method
    # 装饰器作为类方法调用
    @classmethod
    def decorator2(self, func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            print('Decorator 2')
            return func(*args, **kwargs)
        return wrapper


# As an instance method
# 作为实例方法调用
a = A()
@a.decorator1
def spam():
    pass

# As a class method
# 作为类方法调用
@A.decorator2
def grok():
    pass
